<?php

class Jf_Utility_Timer {

    private static $startTimes = array();

    public static $requestTime;

    public static function start () {
        array_push (self::$startTimes, microtime (TRUE));
    }

    public static function stop () {
        return microtime (TRUE) - array_pop (self::$startTimes);
    }

    public static function setRequestTime () {
        if (isset ($_SERVER['REQUEST_TIME_FLOAT'])) {
            self::$requestTime = $_SERVER['REQUEST_TIME_FLOAT'];
        } else {
            self::$requestTime = microtime (TRUE);
        }
    }

    public static function timeSinceStartOfRequest () {
        return round (microtime (TRUE) - self::$requestTime, 8);
    }

    public static function resourceUsage () {
        return sprintf ('Time: %s, Memory: %4.2fMb', self::timeSinceStartOfRequest (), memory_get_peak_usage (TRUE) / 1048576);
    }

}

  
